package bTree.LeetCode;

import java.util.Stack;

public class 用栈实现队列 {
    Stack<Integer>stackA;
    Stack<Integer>stackB;

    public MyQueue() {
        stackA=new Stack<>();
        stackB=new Stack<>();
    }

    public void push(int x) {
        while (!stackB.isEmpty()){
            stackA.add(stackB.pop());
        }
        stackB.add(x);
       while (!stackA.isEmpty()){
           stackB.add(stackA.pop());
       }
    }

    public int pop() {
        return stackB.pop();
    }

    public int peek() {
        return stackB.peek();
    }

    public boolean empty() {
        return stackB.isEmpty();
    }
}